﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SwenAssignment3.Classes;

namespace SwenAssignment3.UserCreationModule
{
    public partial class UserCreation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        protected void tbxUsername_TextChanged(object sender, EventArgs e)
        {

        }

        protected void btnCreate_Click(object sender, ImageClickEventArgs e)
        {
            string user = tbxUsername.Text;
            string staffid = ddlStaffID.Text;
            string password = tbxPassword.Text;
            string accessright = rblAccess.SelectedValue;
           
           
            UserAcc newUser = new UserAcc(user, staffid, password, accessright);
            bool m = DRHotelDBManager.searchUserByUsername(newUser.Username);
            bool n = DRHotelDBManager.searchUserByStaffID(newUser.StaffID);
            if (m == true)
            {
                lblStatusUsername.Text = "Username is already in use";
            }
            else
            {
                if (n == true)
                {
                    lblStatusStaffID.Text = "This staff already had a account";
                }
                else
                {
                    int result = DRHotelDBManager.createNewUser(newUser);
                    if (result == 1)
                    {
                        Session["username"] = tbxUsername.Text;
                        
                        Server.Transfer("UserManagement.aspx?");
                    }
                }
            }


        }

        protected void btnCancel_Click(object sender, ImageClickEventArgs e)
        {

        }

        protected void rblAccess_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}